package util;

import java.security.MessageDigest;

public class MD5Utils {
	public static String getMD5Code(String strObj){
		String resultString = null;
		try{
			resultString = new String(strObj);
			MessageDigest md = MessageDigest.getInstance("MD5");
			resultString = byteToString(md.digest(strObj.getBytes()));
		}catch (Exception e) {
			e.printStackTrace();
		}
		return resultString;
	}

	private static String byteToString(byte[] bytes) {
		String result = "";
		for(int i=0;i<bytes.length;i++){
			int temp = bytes[i] & 0xff;
			String tempHex = Integer.toHexString(temp);
			if(tempHex.length()<2){
				result +="0"+tempHex;
			}else{
				result +=tempHex;
			}
		}
		return result;
	}
}	
